const mutler = require('multer')
const path = require('path')
const storage = mutler.diskStorage({
    destination:function(req,file,callback){
        callback(null,path.resolve(__dirname,'../../public/imgs'));
    },
    filename:function(req,file,callback){
        let originalname = file.originalname;
        let lastIndex=originalname.lastIndexOf('.')+1;
        let suffix = originalname.slice(lastIndex)||file.mimetype.split('/')[1];
        let dt=new Date();
        let yy = dt.getFullYear();
        let mm = dt.getMonth();
        let dd = dt.getDate();
        let str = `${yy}.${mm}.${dd}`
        callback(null,file.fieldname+'-'+str+'-'+Date.now()+'.'+suffix);
    }
});

const upload = mutler({storage:storage});
module.exports=upload